package org.example.studyonline.pojo.DTO;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CourseListDTO {
    private Integer courseID;
    private String name;
    private String desc;
    private String img;
    private Float price;
    private Integer productID;
    @JsonIgnore
    private String category;
    @JsonIgnore
    private String teacher;

    @JsonProperty("category")
    public List<String> getCategoryList() {
        if (category == null || category.isEmpty()) {
            return new ArrayList<>();
        }
        return Arrays.stream(category.split(","))
                .map(String::trim)  // 去除前后空格
                .collect(Collectors.toList());
    }

    @JsonProperty("teacher")
    public List<String> getTeacherList() {
        if (teacher == null || teacher.isEmpty()) {
            return new ArrayList<>();
        }
        return Arrays.stream(teacher.split(","))
                .map(String::trim)  // 去除前后空格
                .collect(Collectors.toList());
    }
}